#include "common.h"

#include "object.h"
#include "asset.h"
#include "mesh.h"
#include "effect.h"
#include "assetmanager.h"

IMPLEMENT_RTTI( Mesh, Asset )

Mesh::Mesh( const std::string& name )
:	Asset( name )
,	_vertexDecl( NULL )
,	_vb( NULL )
,	_ib( NULL )
{
}

Mesh::~Mesh()
{
	if( _vertexDecl )
	{
		_vertexDecl->Release();
		_vertexDecl = NULL;
	}
	if( _vb )
	{
		_vb->Release();
		_vb = NULL;
	}
	if( _ib )
	{
		_ib->Release();
		_ib = NULL;
	}
}

Mesh* Mesh::Create( const std::string& name )
{
	if( AssetManager::Find( name ) )
	{
		return AssetManager::GetMesh( name );
	}

	Mesh* pMesh = new Mesh( name );
	AssetManager::Register( name, pMesh );
	return pMesh;
}
